package DGWeb.Servlets;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.SingleThreadModel;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;

import DGWeb.Model.model_MessageInsert;

/**
 * Servlet implementation class SetTopicText
 */
@SuppressWarnings("deprecation")
@WebServlet("/SetTopicText")
public class SetTopicText extends HttpServlet implements SingleThreadModel {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SetTopicText() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		HttpSession UserSession = request.getSession();
		InputStreamReader isr = new InputStreamReader(request.getInputStream());
		BufferedReader br = new BufferedReader(isr);
		Gson json = new Gson();
		model_MessageInsert c = json.fromJson(br.readLine(), model_MessageInsert.class); // I only need the Text
		
		br.close();
		isr.close();
		if ( c.getText() != null)
			UserSession.setAttribute("Topic", c.getText());
		
	}

}
